import axios from 'axios'
import qs from 'qs'

//创建一个axios对象
let http = axios.create({
//  根路径
  baseURL: 'http://localhost:8000/',
// //  连接超时时间
  //   timeout: 100000000,
//  是否携带凭证
  withCredentials: true,
})

http.interceptors.request.use(config => {
  if (config.method='post') {
    // 获取token
    let token = sessionStorage.getItem('token')
    if (token != null || token != undefined) {
      config.headers = {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'bearer' + token
      }
    }
  }
  // console.log(config)
  return config
})

http.interceptors.response.use(responce => {
  // console.log("拦截响应："+responce.data);
  return responce.data
})

export default http
